from flask import Flask, url_for, request, render_template

app = Flask(__name__)


@app.route('/')
def hello_world():
    return render_template('index.html')


@app.route('/search')
def search():
    q = request.args.get('q')
    return q


# login方法支持两个请求，get用于返回模板，post用于提交表单，这里需要写明支持的请求类型
@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'GET':
        return render_template('login.html')
    else:
        username = request.form.get('username')
        password = request.form.get('password')
        return username + ' ' + password


if __name__ == '__main__':
    app.run(debug=True)
